package stackDemo;

import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[10];
    }
    //入栈
    public void push(int val) {
        //1.满了进行扩容
        if(isFull()) {
            elem = Arrays.copyOf(elem,elem.length*2);
        }
        //2.插入
        elem[usedSize] = val;

        //3.usedSize++
        usedSize++;
    }
    public Boolean isFull() {
        return elem.length == usedSize;
    }
    //出栈
    public int pop() {
        if(isEmpty()) {
            return -1;
        }
        int oldVal = elem[usedSize-1];
        usedSize--;
        return oldVal;
    }
    public Boolean isEmpty() {
        return usedSize == 0;
    }
    //只看不出
    public int peek() {
        if(isEmpty()) {
            return -1;
        }
        return elem[usedSize-1];
    }
    public int getUsedSize() {
        return usedSize;
    }
}
